﻿<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link href="/style/rightdirectory.css" rel="stylesheet" />
    <script src="/script/config.js"></script>
</head>

<body>
    <h5>管理员列表</h5>

    <div class="form-body">
        <div class="form-horizontal  hide" id="form">

        </div>
    </div>
</body>
</html>
<script type="text/html" id="tp-form">
   
    <div class="form-group">
        <label class="col-sm-2">真实姓名</label>
        <div class="col-md-6 col-sm-10">
            <input maxlength="20" type="text" class="form-control" data-form="RealName" placeholder="真实姓名" value="{{RealName}}">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2">电话</label>
        <div class="col-md-6 col-sm-10">
            <input maxlength="11" type="text" class="form-control" data-form="Phone" placeholder="电话" value="{{Phone}}">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2">邮箱</label>
        <div class="col-md-6 col-sm-10">
            <input  maxlength="20"  type="text" class="form-control" data-form="Email" placeholder="邮箱" value="{{Email}}">
        </div>
    </div>

    {{if PageId<=0}}
    <div class="form-group">
        <label class="col-sm-2">账号</label>
        <div class="col-md-6 col-sm-10">
            <input maxlength="20" type="text" class="form-control" data-form="Account" placeholder="账号" value="{{Account}}">
        </div>
    </div>

    <div class="form-group" id="Pwd">
        <label class="col-sm-2">密码</label>
        <div class="col-md-6 col-sm-10">
            <input maxlength="20" type="password" class="form-control" data-form="Pwd" placeholder="密码" value="{{Pwd}}">
        </div>
    </div>
    {{/if}}
    <div class="form-group">
        <label class="col-sm-2">账户状态</label>
        <div class="col-sm-2 col-sm-10">
            <label class="radio-reset">
                <input type="radio" name="n" data-form="Status" value="1" {{Status|radio_checked 1}}>
                <span>正常</span>
            </label>
            <label class="radio-reset">
                <input type="radio" name="n" data-form="Status" value="2" {{Status|radio_checked 2}}>
                <span>冻结</span>
            </label>
        </div>
    </div>
   
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="button" id="btn-submit" class="btn btn-primary">保存</button>
            <button type="button" class="btn" onclick="window.history.go(-1)">退出</button>
        </div>
    </div>
</script>
<link href="/script/valid/css/tr.css" rel="stylesheet" /><!--判断如：PlatformName格式-->
<script src="/script/valid/form-valid.js?v=2018"></script>
<script>
    $(function () {
        var id = QueryPageUrlString("v");//判断是否是编辑进来的
        var formValidEvent;
        var formValidInit = function () {
            var formValidData = [
                {
                    key: "RealName",
                    datatype: "s2-16",
                    nullmsg: "不能为空哦",
                    errormsg: "两个以上的文字"
                },{
                    key: "Phone",
                    datatype:  "m",
                    nullmsg: "请正确输入手机号！",
                    errormsg: "请正确输入手机号！"
                },
                {
                    key: "Email",
                    datatype: "*",
                    nullmsg: "不能为空哦",
                    errormsg: "不能为空哦"
                },
                {
                    key: "Age",
                    datatype: "n",
                    nullmsg: "不能为空哦",
                    errormsg: "请正确输入！"
                },
                {
                    key: "Sex",
                    datatype: "s1-1",
                    nullmsg: "不能为空哦",
                    errormsg: "请正确输入！"
                },
                {
                    key: "Account",
                    datatype: "*2-16",
                    nullmsg: "不能为空哦",
                    errormsg: "账号范围在2~16位之间！！"
                },
                {
                    key: "Pwd",
                    datatype: "*6-16",
                    nullmsg: "请设置密码！",
                    errormsg: "密码范围在6~16位之间！"
                },


            ];
            formValidEvent = $(".form-body").formValid(formValidData);
        }
        var inintData = {
            RealName: "",
            Phone: "",
            Email: "",
            Account: "",
            Pwd: "",
            Status: 1,
            PageId: id,
        };
        if (id > 0) { //存在值的情况
            $.http.json("user/find", {   //查询
                Id: id
            }, {
                pass: function (data) {
                    $("#form").templateRender({ el: "tp-form", data: data });
                    formValidInit();
                },
                error: function (d) {
                    console.log(d);
                }
            })
        } else {
            $("#form").templateRender({ el: "tp-form", data: inintData });
            formValidInit();
        }
        $("#form").on("click", "#btn-submit", function () { //保存按钮有添加和编辑
            if (!formValidEvent.check()) { return; }
            var apiUrl = "user/insert";
            if (id > 0) {
                apiUrl = "user/upd";
            }
            $("#form").ajaxFormSubmit(apiUrl, {
                pass: function (d) {
                    $.msgSucceed(d.Errmsg);
                },
                error: function (d) {
                    console.log(d)
                    $.msgFall(d.Errmsg);
                }
            }, { addData: {Id:id}})

        })

    })
</script>
